#include "flash.h"

void FLASH_Init(void)
{
    FLASH_DeInit();
}

void Flash_WriteByte(u32 addr, u8 data)
{
    FLASH_Unlock(FLASH_MEMTYPE_DATA);
    FLASH_ProgramByte(addr, data);
    FLASH_Lock(FLASH_MEMTYPE_DATA);
}

u8 Flash_ReadByte(u32 addr)
{
    return FLASH_ReadByte(addr);
}

void Flash_ReadBuffer(u32 addr, u8 *pbuf, u16 size)
{
    for (int i = 0; i < size; i++)
    {
        pbuf[i] = FLASH_ReadByte(addr + i);
    }
}

void Flash_WriteBuffer(u32 addr, u8 *pBuf, u16 size)
{
    FLASH_Unlock(FLASH_MEMTYPE_DATA);
    for (int i = 0; i < size; i++)
    {
        FLASH_ProgramByte(addr + i, *pBuf++);
    }
    FLASH_Lock(FLASH_MEMTYPE_DATA);
}
